package com.pug.zixun.controller.questionscomment;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.pug.zixun.service.questionscomment.IQuestionsCommentService;
import com.pug.zixun.pojo.QuestionsComment;
import com.pug.zixun.vo.QuestionsCommentVo;
import com.pug.zixun.bo.QuestionsCommentBo;
import com.pug.zixun.commons.enums.ResultStatusEnum;
import com.pug.zixun.commons.ex.PugValidatorException;
import com.pug.zixun.commons.utils.fn.asserts.Vsserts;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import com.pug.zixun.controller.BaseController;
import java.util.List;
import org.pug.generator.anno.PugDoc;
/**
 * QuestionsCommentController
 * 创建人:yykk<br/>
 * 时间：2022-08-09 22:11:35 <br/>
 * 源码下载：前台代码 git clone https://gitee.com/kekesam/kuangstudy-pug-ui.git
 * 飞哥B站地址：后台代码 git clone https://gitee.com/kekesam/kuangstudy-pug-parent.git
 * @version 1.0.0<br/>
 *
*/

@RestController
@RequiredArgsConstructor
@Slf4j
@PugDoc(name="文章评论",tabname="kss_question_comment")
public class QuestionsCommentController extends BaseController{

    private final IQuestionsCommentService questionscommentService;


    /**
     * 查询文章评论列表信息
     * @path : /admin/questionscomment/list
     * @method: findQuestionsComments
     * @result : List<QuestionsCommentBo>
     * 创建人:yykk
     * 创建时间：2022-08-09 22:11:35
     * @version 1.0.0
     * @return
     */
    @PostMapping("/questionscomment/list")
    @PugDoc(name="查询文章评论列表信息")
    public List<QuestionsCommentBo> findQuestionsCommentList() {
        return questionscommentService.findQuestionsCommentList();
    }

	/**
	 * 查询文章评论列表信息并分页
	 * @path : /admin/questionscomment/load
     * @method: findQuestionsComments
     * @param : questionscommentVo
     * @result : IPage<QuestionsCommentBo>
	 * 创建人:yykk
	 * 创建时间：2022-08-09 22:11:35
	 * @version 1.0.0
	*/
    @PostMapping("/questionscomment/load")
    @PugDoc(name="查询文章评论列表信息并分页")
    public IPage<QuestionsCommentBo> findQuestionsComments(@RequestBody QuestionsCommentVo questionscommentVo) {
        return questionscommentService.findQuestionsCommentPage(questionscommentVo);
    }


    /**
     * 根据文章评论id查询明细信息
     * @method: get/{id}
     * @path : /admin/questionscomment/get/{id}
     * @param : id
     * @result : QuestionsCommentBo
     * 创建人:yykk
     * 创建时间：2022-08-09 22:11:35
     * @version 1.0.0
    */
    @PostMapping("/questionscomment/get/{id}")
    @PugDoc(name="根据文章评论id查询明细信息")
    public QuestionsCommentBo getQuestionsCommentById(@PathVariable("id") String id) {
        if(Vsserts.isEmpty(id)){
           throw new PugValidatorException(ResultStatusEnum.ID_NOT_EMPTY);
        }
        return questionscommentService.getQuestionsCommentById(new Long(id));
    }


	/**
	 * 保存和修改文章评论
     * @method: saveupdate
	 * @path : /admin/questionscomment/save
     * @param : questionscomment
     * @result : QuestionsCommentBo
	 * 创建人:yykk
	 * 创建时间：2022-08-09 22:11:35
	 * @version 1.0.0
	*/
    @PostMapping("/questionscomment/saveupdate")
    @PugDoc(name="保存和修改文章评论")
    public QuestionsCommentBo saveupdateQuestionsComment(@RequestBody QuestionsComment questionscomment) {
        return questionscommentService.saveupdateQuestionsComment(questionscomment);
    }


    /**
	 * 根据文章评论id删除文章评论
     * @method: delete/{id}
     * @path : /admin/questionscomment/delete/{id}
     * @param : id
     * @result : int
	 * 创建人:yykk
	 * 创建时间：2022-08-09 22:11:35
	 * @version 1.0.0
	*/
    @PostMapping("/questionscomment/delete/{id}")
    @PugDoc(name="根据文章评论id删除文章评论")
    public int deleteQuestionsCommentById(@PathVariable("id") String id) {
        if(Vsserts.isEmpty(id)){
            throw new PugValidatorException(ResultStatusEnum.ID_NOT_EMPTY);
        }
        return questionscommentService.deleteQuestionsCommentById(new Long(id));
    }


   /**
   	 * 根据文章评论ids批量删除文章评论
     * @method: questionscomment/delBatch
     * @path : /admin/questionscomment/delBatch
     * @param : questionscommentVo
     * @result : boolean
   	 * 创建人:yykk
   	 * 创建时间：2022-08-09 22:11:35
   	 * @version 1.0.0
   	*/
    @PostMapping("/questionscomment/delBatch")
    @PugDoc(name="根据文章评论ids批量删除文章评论")
    public boolean delQuestionsComment(@RequestBody QuestionsCommentVo questionscommentVo) {
        log.info("你要批量删除的IDS是:{}", questionscommentVo.getBatchIds());
        if (Vsserts.isEmpty(questionscommentVo.getBatchIds())) {
            throw new PugValidatorException(ResultStatusEnum.ID_NOT_EMPTY);
        }
        return questionscommentService.delBatchQuestionsComment(questionscommentVo.getBatchIds());
    }
}